package com.hqyj.mqservice;

import com.hqyj.websocket.EmailWebSocket;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * @Description
 * @Autor 伍军
 * @Date 2022/10/17 16:03
 * @Version 1.0
 **/
@Component
public class MqServer {

    /**
     * //监听队列helloQueue01的消息
     * @param c 频道： 提供手动消费的方法
     * @param message 消息对象
     * @param map 消息参数
     */
    @RabbitListener(queues = "helloQueue01")
    public void getInfo(Channel c, Message message, Map<String,Object> map) throws IOException {

       /* System.out.println("获取队列的消息编号:"+message.getMessageProperties().getDeliveryTag());

        System.out.println("用户名："+map.get("userName"));
        System.out.println("密码："+map.get("userPwd"));

        String info = new String(message.getBody());
        System.out.println("消息信息"+info);


*/
        String email = map.get("email")+"";
        String id = map.get("id")+"";
        System.out.println("调用邮箱发送的service");
        //假设调用邮箱发送成功和失败的信息
        //调用发送消息的方法
        EmailWebSocket.sendMsg(id,"发送邮箱成功");


    }

    @RabbitListener(queues = "helloQueue02")
    public String getInfo01(Channel c, Message message, Map<String,Object> map){

        //拿到了用户名和密码,调用数据数据的登录验证方法

        return "登录成功";
    }


}
